package hotelscenter;

/*
 * ZooServlet.java
 *
 * Created on March 20, 2004, 10:43 AM
 */

import javax.servlet.*;
import javax.servlet.http.*;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
import org.w3c.dom.*;

/**
 * A servlet to display the animals.
 *
 * @author Philippe Poulard
 */
public class Moteur {

    public final static String XML_PATH = "home.xml";
    
    /**
     * 
     * @param chemin_xsl
     * @param webApp
     * @param request
     * @param response
     * @throws ServletException 
     */
    public void genererPage(String chemin_xsl, ServletContext webApp, HttpServletRequest request, HttpServletResponse response) throws ServletException {
        
        try {
            
            // Get concrete implementation
            TransformerFactory tFactory = TransformerFactory.newInstance();
            // Create a reusable templates for a particular stylesheet
            Templates templates = tFactory.newTemplates(new StreamSource(webApp.getRealPath(chemin_xsl)));
            // Create a transformer
            Transformer transformer = templates.newTransformer();
            
            // Get concrete implementation
            DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance();
            // Need a parser that support namespaces
            dFactory.setNamespaceAware(true);
            // Create the parser
            DocumentBuilder parser = dFactory.newDocumentBuilder();
            // Parse the XML document
            Document doc = parser.parse(webApp.getRealPath(XML_PATH));
            // Get the XML source
            Source xmlSource =  new DOMSource(doc);
            
            response.setContentType("text/html");
            // Transform input XML doc in HTML stream
            transformer.transform(xmlSource, new StreamResult(response.getWriter()));
            
        } catch (Exception ex) {
            throw new ServletException( ex );
        }
        
    }
    
}